package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.BuyGuankanquanInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;
import com.xgkj.diyiketang.util.LogUtils;

/**
 * Created by Tao on 2017/6/23.
 */

public class BuyGuankanquanTask extends CouponHttpBaseTask {
    private String mSize;
    private String mPageNo;
    private String mQuotaid;
    private String mType;
    public BuyGuankanquanTask(String size, String pageNo,String quotaId,String type) {
        super(TaskType.BANGDINGSHOUJI_TASK);
        mSize = size;
        mPageNo = pageNo;
        mQuotaid = quotaId;
        mType = type;
    }
    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject responseBody = response.getBody();
        BuyGuankanquanInfo orderInfo = null;
        if (responseBody != null){
            orderInfo = JSON.parseObject(responseBody.toString(),BuyGuankanquanInfo.class);
        }
        notifyTaskCompleted(TaskResultCode.SUCCESS,orderInfo);
    }
    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT) {
            CouponHttpRequest request = new CouponHttpRequest(RequestType.BUY_GUANKANQUAN);
            JSONObject json = new JSONObject();
            json.put("size", mSize);
            json.put("pageNo", mPageNo);
            json.put("quotaId", mQuotaid);
            json.put("type", mType);
            request.setData(json.toString());
            request.setApiNo(ApiNo.BUYGUANKANQUAN);
            addRequest(request);
        }
    }
}
